// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由
import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'
import Login from '@/views/login/index.vue'
import Home from '@/views/layout/home/index.vue'
import Category from '@/views/layout/category/index.vue'
import SubCategory from '@/views/layout/category/sub/subCategory.vue'
import Detail from '@/views/layout/detail/index.vue'

//
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Layout',
      component: Layout,
      children: [
        {
          //默认渲染，当访问路径是 “/”时，会渲染这个组件，叫做默认二级路由
          path: '',
          component: Home,
        },
        {
          path: 'category/:id',
          component: Category,
        },
        {//二级分类。 属于是三级路由，但是占着 二级路由的出口
          path: 'category/sub/:id',
          component: SubCategory,
        },
        {//详情，目前就对 首页中的新鲜好物 进行处理
          path: 'detail/:id',
          component: Detail,
        }
      ]
    },
    {
      path: '/login',
      name: 'Login',
      component: Login,
    }
  ],
  //路由滚动行为
  scrollBehavior(to, from, savedPosition) {
    // return 期望滚动到哪个的位置。最顶部和最左边
    return { left: 0, top: 0 }
  }
})

export default router
